Ext.define('StaffServer.controller.TeacherHisController', {
	extend : 'Ext.app.Controller',

	models: ['TeacherHisModel'],
	stores: ['TeacherHisStore'],
	views:  ['teacherhis.TeacherHisGrid', 
	         
	         'teacherhis.TeacherHisMngr', 
	         'teacherhis.TeacherHisSearchPanel', 
	         'teacherhis.TeacherHisForm', 
	         'teacherhis.TeacherHisWindow'
	      ],
	
	tabView: 'StaffServer.view.teacherhis.TeacherHisMngr',
	
	teacherHisWindow:null,
	teacherHisForm:null,
	
	submitFlag: null,
	retireId: null,
	
	refs : [ {
		ref : 'teacherHisSearchPanel',
		selector : 'teacherHisSearchPanel'
	}, {
		ref : 'teacherHisGrid',
		selector : 'teacherHisGrid'
	}],

	// 初始化执行语句
	init : function() {
		teacherHisWindow = Ext.widget("teacherHisWindow");
		teacherHisForm = Ext.ComponentQuery.query('teacherHisForm')[0];

		
		
		// 控制事件
		this.control({
			'teacherHisSearchPanel button[action=search]' : {
				click : this.search
			},
			'teacherHisSearchPanel button[action=reset]' : {
				click : this.reset
			},
			
			
			
			'teacherHisWindow button[action=submit]' : {
				click : this.submitWindow
			},
			'teacherHisWindow button[action=close]' : {
				click : this.closeWindow
			},
			
			'teacherHisGrid': {
				itemdblclick: this.updateTeacher
			}
		});
	},

	
	
	//searchPanel查询
	search : function() {
		var searchPanel = this.getTeacherHisSearchPanel();
		var grid = this.getTeacherHisGrid();
		grid.store.on('beforeload', function(store){
			var searchParams = searchPanel.getForm().getFieldValues();
			Ext.apply(store.proxy.extraParams, searchParams);
        });
		Ext.ComponentQuery.query('teacherHisGrid > pagingtoolbar')[0].moveFirst();
	},
	
	//searchPanel重置
	reset: function(){
		var searchPanel = this.getTeacherHisSearchPanel();
		searchPanel.getForm().reset();
	},
	
	
	
	//更新
	updateTeacher: function(){
		var record = this.getTeacherHisGrid().getSelectionModel().getLastSelected();
        if (Ext.isEmpty(record)) {
            Ext.Msg.alert('提示', '请先选择要操作的记录!');
            return;
        }
        //Ext.ComponentQuery.query('teacherHisForm')[0].setReadOnly(true);
        teacherHisForm.loadRecord(record);
  

        submitFlag = "update";
        teacherHisWindow.setTitle("修改退休人员信息");
        teacherHisWindow.show();
        var myphoto= Ext.ComponentQuery.query('teacherHisForm [name="teacherpic"]')[0];    
        myphoto.getEl().dom.src ='pic/teacher'+record.data.staffId+'.jpg';
	},
	
	
	
	
	
	//关闭窗口
	closeWindow: function(){
		teacherHisForm.getForm().reset();
		teacherHisWindow.hide();
	}
	
	
	
	
	
	
	
	
});